import Vue from 'vue'
import Vuex from 'vuex'
import { setItem ,getItem} from '@/utils/storage'

Vue.use(Vuex)
const userKey = 'TOUTIAO_USER'
// const user = getItem(userKey)
export default new Vuex.Store({
  state: {
    user:getItem(userKey) || {}
  },
  getters: {
    token:(state) => state.user.token
  },
  mutations: {
    setUser(state,data) {
      //形参1是state,形参2是调用这个方法传入的数据
      state.user = data
      setItem(userKey,data)
    }
  },
  actions: {
  },
  modules: {
  }
})

